<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layui/others/dtree/dtree.css">
    <link rel="stylesheet" href="/static/layui/others/dtree/font/dtreefont.css">
    <!--预警闸值设置页面-->
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>计量设备状态停留时间预警闸值设置</legend>
</fieldset>
<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title layui-elem-quote">计量设备状态预警参数设置</h2>
        <div class="layui-colla-content layui-show">
            <form class="layui-form" action="" id="searchForm"><input name="id" type="hidden" th:value="${selected[0]['id']}">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">供电单位</label>
                        <div class="layui-input-inline" style="z-index:998; width:500px;">
                            <ul id="iframeTree2" class="dtree" data-id="00"></ul>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">设备类别</label>
                        <div class="layui-input-inline">
                            <ul id="iframeTree3" class="dtree" data-id="00"></ul>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" lay-submit lay-filter="configSubmit" class="layui-btn layui-btn-sm">更新</button>
                        <button type="reset" id="selTree6_btn" class="layui-btn layui-btn-sm">清空</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-colla-item">
        <h2 class="layui-colla-title layui-elem-quote">计量设备状态定时扫描设置</h2>
        <div class="layui-colla-content">
            <form class="layui-form" action=""><input type="hidden" id="scanHoursHidden" th:value="${scanHours}">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px;">定时扫描时间</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="scanHours" lay-verify="required|number"
                                   autocomplete="off"
                                   class="layui-input" th:value="${scanHours}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">小时</div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" lay-submit lay-filter="scanHoursSubmit" class="layui-btn layui-btn-sm">更新
                        </button>
                        <button type="reset" class="layui-btn layui-btn-sm layui-btn-slight">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-colla-item" th:each="m:${levelData}">
        <h2 class="layui-colla-title layui-elem-quote" th:text="'计量设备状态：'+${m.name}">计量设备状态：无数据</h2>
        <div class="layui-colla-content">
            <form class="layui-form" action=""><input type="hidden" name="id" th:value="${m.id}">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px;">正常停留时间</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="normalTime" lay-verify="required|number"
                                   autocomplete="off"
                                   class="layui-input" th:value="${m.normalTime}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">小时</div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px;">预警阀值-轻微</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="slight" lay-verify="required|number"
                                   autocomplete="off"
                                   class="layui-input" th:value="${m.slight}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">小时</div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px;">预警阀值-中级</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="middle" lay-verify="required|number"
                                   autocomplete="off"
                                   class="layui-input" th:value="${m.middle}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">小时</div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px;">预警阀值-严重</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="high" lay-verify="required|number" autocomplete="off"
                                   class="layui-input" th:value="${m.high}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">小时</div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" lay-submit lay-filter="checkNumber" class="layui-btn layui-btn-sm">更新
                        </button>
                        <button type="reset" class="layui-btn layui-btn-sm layui-btn-slight">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script th:inline="javascript">
    var $, element, layer, form, dtree;
    var panlongQuID="0501";
    layui.extend({
        dtree: '{/}/static/layui/others/dtree/dtree'
    }).use(['element', 'layer', 'form', 'dtree'], function () {
        $ = layui.jquery;
        element = layui.element;
        layer = layui.layer;
        dtree = layui.dtree;
        form = layui.form;
        var iframeTree2=dtree.render({
            elem: "#iframeTree2",
            data: [[${devRegion}]],
            dataStyle: "layuiStyle",
            dataFormat: "list",
            response: {
                message: "total", statusName: "total", statusCode: "200", rootName: 'rows',
                treeId: "id", parentId: "p_id", title: "name", checkArr:"code"
            },
            record: true,
            method: "GET",
            initLevel: 2,
            select: true,
            width: "100%",
            icon: "-1",
            skin: "layui",
            selectTips: "请选择..",
            selectInputName: {
                nodeId: "name"
            },
            checkbar:true,
            checkbarType: "p-casc",
            done: function(res, $ul, first){
                if(first) {
                    dtree.chooseDataInit("iframeTree2",[[${selected[0]["gddwdbm"]}]]);
                    dtree.selectVal("iframeTree2");
                }
            }
        });
        //树2
        var data=[
            {"id":"01","title": "电能表","code": "0","parentId": "00"},
            {"id":"02","title": "互感器","code": "0","parentId": "00"},
            {"id":"03","title": "负荷管理终端","code": "0","parentId": "00"},
            {"id":"04","title": "配变监测计量终端","code": "0","parentId": "00"},
            {"id":"05","title": "集中器","code": "0","parentId": "00"},
            {"id":"06","title": "采集器","code": "0","parentId": "00"},
            {"id":"07","title": "厂站电能量采集终端","code": "0","parentId": "00"},
            {"id":"08","title": "售电管理装置","code": "0","parentId": "00"},
            {"id":"09","title": "计量封印","code": "0","parentId": "00"},
            {"id":"10","title": "计量表箱","code": "0","parentId": "00"},
            {"id":"11","title": "计量柜","code": "0","parentId": "00"},
            {"id":"12","title": "SIM卡","code": "0","parentId": "00"},
            {"id":"13","title": "电能计量标准装置","code": "0","parentId": "00"},
            {"id":"14","title": "电能计量标准器","code": "0","parentId": "00"},
            {"id":"15","title": "配套设备","code": "0","parentId": "00"},
            {"id":"16","title": "测试设备","code": "0","parentId": "00"},
            {"id":"17","title": "型式试验设备","code": "0","parentId": "00"},
            {"id":"18","title": "其他装置","code": "0","parentId": "00"},
            {"id":"19","title": "电能表检测设备","code": "0","parentId": "00"},
            {"id":"20","title": "其它检测设备","code": "0","parentId": "00"},
            {"id":"23","title": "互感器检测设备","code": "0","parentId": "00"}
        ];

        var iframeTree3=dtree.render({
            elem: "#iframeTree3",
            data: data,
            dataStyle: "layuiStyle",
            dataFormat: "list",
            response: {
                message: "total", statusName: "total", statusCode: "200", rootName: 'rows',
                treeId: "id", parentId: "parentId", title: "title", checkArr:"code"
            },
            initLevel: 2,
            select: true,
            width: "100%",
            icon: "-1",
            ficon: "-1",
            skin: "layui", //样式
            selectTips: "请选择..",
            selectInputName: {
                nodeId: "normalTime"
            },
            checkbar:true,
            checkbarType: "p-casc", //选择类型
            done: function(res, $ul, first){
                if(first) {
                    dtree.chooseDataInit("iframeTree3",[[${selected[0]["sblbdm"]}]]);
                    dtree.selectVal("iframeTree3");
                }
            }
        });
        $("body").on("click", function (event) {
            $("div[dtree-id][dtree-select]").removeClass("layui-form-selected");
            $("div[dtree-id][dtree-card]").removeClass("dtree-select-show layui-anim layui-anim-upbit");
        });
        //清空选择
        $("#selTree6_btn").click(function(){
            iframeTree2.selectResetVal();
            iframeTree3.selectResetVal();
        });
        form.on('submit(checkNumber)', function (data) {
            if (parseInt(data.field.normalTime) < parseInt(data.field.slight)) {
                if (parseInt(data.field.slight) < parseInt(data.field.middle)) {
                    if (parseInt(data.field.middle) < parseInt(data.field.high)) {
                        $.post('/devices?thresholdLevelSetTab', data.field, function (success) {
                            if (success == "") {
                                layer.msg("更新成功");
                            } else {
                                layer.msg("更新失败");
                            }
                        });
                        return;
                    }
                }
            }
            layer.msg("输入的内容有误或不匹配");
        });
        //扫描时间提交
        form.on('submit(scanHoursSubmit)', function (data) {
            if (data.field.scanHours != $("#scanHoursHidden").val()) {
                $.post('/devices/scanHoursSet', data.field, function (success) {
                    if (success == "") {
                        layer.msg("更新成功,将立即生效");
                    } else {
                        layer.msg("更新失败");
                    }
                });
            }else{
                layer.msg("内容重复");
            }
        });
        //配置提交
        form.on('submit(configSubmit)', function (data) {
            if (data.field.name=="" ||data.field.normalTime=="") {
                layer.msg("至少选择一项");
                return;
            }
            $.post('/devices/thresholdLevelSet', data.field, function (success) {
                if (success == "") {
                    layer.msg("更新成功,最近一次扫描时生效");
                } else {
                    layer.msg("更新失败,请减少供电单位选项");
                }
            });

        });
    });
</script>

</body>
</html>